<?php
/**
 * 订单接口
 * @Author: phpzhi <phpzhi@qq.com><https://www.phpzhi.com>
 * @Date: 2019/11/8 11:46
 */

namespace app\api\controller;


use app\api\model\goods\GoodsOrder;
use app\common\controller\Api;
use app\api\model\goods\GoodsCart;
use app\common\model\user\Address;

class Order extends Api
{
    protected $noNeedRight = ['*'];
    /**
     * 订单列表
     */
    public function index()
    {
        //
    }

    /**
     * 提交订单
     */
    public function confirm()
    {
        $cartId = $this->request->request('id');
//        if (!is_numeric($cartId) || !$cartId)
//            $this->error('404 Not Found!');

        $goodsInfo = GoodsCart::getUserCartList($this->auth->id, $cartId, 1);
        halt($goodsInfo);
        if (count($goodsInfo['invalid'])) $this->error('该商品已失效');
        if (!$goodsInfo['valid']) $this->error('请提交购买的商品');

        //$cartInfo = $cartGroup['valid'];
        $priceInfo = GoodsOrder::getOrderPriceInfo($goodsInfo);

        // 获取用户默认地址
        $addressInfo = Address::getUserDefaultAddress($this->auth->id);

        $this->success(__('Request successful'), compact('goodsInfo','priceInfo', 'addressInfo'));
    }

    /**
     * 订单生成并支付
     * @param int $id 购物车id
     */
    public function create($id)
    {
        //
    }

    /**
     * 订单详情
     * @param int $id 订单id
     */
    public function view($id)
    {
        //
    }

    /**
     * delete completed order.
     * @param int $id
     */
    public function delete($id)
    {
        //
    }

    /**
     * cancel this order
     * @param $id
     */
    public function cancel($id)
    {
        //
    }

    /**
     * 支付结果
     * @param int $id 订单id
     */
    public function payresult($id)
    {
        //
    }

    /**
     * confirmation receipt order.
     * @param int $id order id
     */
    public function receipt($id)
    {
        //
    }

    /**
     * order again.
     * @param int $id
     */
    public function again($id)
    {
        //
    }

    /**
     * order return apply.
     * @param int $id order id
     */
    public function refund($id)
    {
        //
    }

    /**
     * order return list.
     */
    public function refundlist()
    {
        //
    }

    /**
     * view order logistics.
     * @param $id
     */
    public function logistics($id)
    {
        //
    }

    /**
     * comment this order.
     * @param $id
     */
    public function comment($id)
    {
        //
    }
}
